<?php include '_init_.php';?>
<?php include 'page_header.php';?>
<?php
$id = isset($_REQUEST['id'])?intval($_REQUEST['id']):0;
if($id < 1)
	exit("Please specify ID");
$orderManager = Order_Manager::getOrderManager($_REQUEST['id']);
if(!$orderManager)
	exit('Data not exist anymore');
if($orderManager->getStatus() != Order_Manager::$STATUS_CREATING)
{
	exit("Order doesn't editable");
}
$orderManager->setEditing();

$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if($act == 'save')
{
	$setInfo = array();
	$setInfo['photo_time'] = strlen($_REQUEST['photo_time']) > 0?$_REQUEST['photo_time'].' '.$_REQUEST['photo_time_time']:'';
	$setInfo['proof_time'] = strlen($_REQUEST['proof_time']) > 0?$_REQUEST['proof_time'].' '.$_REQUEST['proof_time_time']:'';
	$setInfo['pickup_time'] = strlen($_REQUEST['pickup_time']) > 0?$_REQUEST['pickup_time'].' '.$_REQUEST['pickup_time_time']:'';
	$setInfo['photo_person_list'] = isset($_REQUEST['photo_person_list'])?$_REQUEST['photo_person_list']:array();
	$setInfo['dress_person_list'] = isset($_REQUEST['dress_person_list'])?$_REQUEST['dress_person_list']:array();
	$orderManager->setWorkflowInfo($setInfo);
	$orderManager->persistOrderInfo();
	$orderManager->setNotEditing();
	header('Location:add-cose.php?id='.$orderManager->getId());
	exit();
}


$orderManager->init();
$pageInfo = $orderManager->getWorkflowInfo();

$pageInfo['photo_time'] = trim($pageInfo['photo_time']);
$pageInfo['proof_time'] = trim($pageInfo['proof_time']);
$pageInfo['pickup_time'] = trim($pageInfo['pickup_time']);

if(strlen($pageInfo['photo_time']) > 0)
{
	$objDatetime = strtotime($pageInfo['photo_time']);
	$pageInfo['photo_time'] = date(constant('WEBSITE_DATE_FORMATE'),$objDatetime);
	$pageInfo['photo_time_time'] = date('H:00:00',$objDatetime);
}

if(strlen($pageInfo['proof_time']) > 0)
{
	$objDatetime = strtotime($pageInfo['proof_time']);
	$pageInfo['proof_time'] = date(constant('WEBSITE_DATE_FORMATE'),$objDatetime);
	$pageInfo['proof_time_time'] = date('H:00:00',$objDatetime);

}
if(strlen($pageInfo['pickup_time']) > 0)
{
		$objDatetime = strtotime($pageInfo['pickup_time']);
	$pageInfo['pickup_time'] = date(constant('WEBSITE_DATE_FORMATE'),$objDatetime);
	$pageInfo['pickup_time_time'] = date('H:00:00',$objDatetime);

}

$orderInfo = $orderManager->getInfo();
?>
<script language="javascript">
$(function() {
	//apply data
	$('input[name=photo_time]').val('<?php echo $pageInfo['photo_time'];?>');
	$('input[name=proof_time]').val('<?php echo $pageInfo['proof_time'];?>');
	$('input[name=pickup_time]').val('<?php echo $pageInfo['pickup_time'];?>');
	
	$('select[name=photo_time_time] option[value="<?php echo $pageInfo['photo_time_time'];?>"]').attr('selected',true);
	$('select[name=proof_time_time] option[value="<?php echo $pageInfo['proof_time_time'];?>"]').attr('selected',true);
	$('select[name=pickup_time_time] option[value="<?php echo $pageInfo['pickup_time_time'];?>"]').attr('selected',true);
	
	<?php foreach($pageInfo['photo_person_list'] as $tmpData):?>
	<?php if(strlen(trim($tmpData)) > 0):?>
	$('.jq_html_selector_photo[value="<?php echo $tmpData;?>"]').attr('checked',true);
	<?php endif;?>
	
	<?php endforeach;?>
	<?php foreach($pageInfo['dress_person_list'] as $tmpData):?>
	<?php if(strlen(trim($tmpData)) > 0):?>
	$('.jq_html_selector_dress[value="<?php echo $tmpData;?>"]').attr('checked',true);
	<?php endif;?>
	<?php endforeach;?>
});
</script>
<div id="main"><!-- start #main //-->
<form method="post" action='add-cosd.php'>
<input type="hidden" name="act" value="save"/>
<input type="hidden" name="id" value="<?php echo $orderManager->getId();?>"/>
<div id="tita">
  <div class="tita-1">
    <h3>工作排程</h3>
    <img src="images/point-1.gif" width="18" height="18" /> 
    <h4>日期</h4>
    <img src="images/point-1.gif" width="18" height="18" /> 
    <h4>人員設定</h4>
    </div>
  <div class="tita-2">預約單號 No.<?php echo Util::html_safe($orderInfo['number']);?></div>
  </div>
  <div id="mainf" class="clearfix"><!-- start #mainf //-->

    <div class="mainf-3">
      <ul>
     <li class="mainf-1g">拍照</li><li class="mainf-1g2"><input name="photo_time" type="text"  class="maine-keyini datepicker _validate_form_required"/> 
     	<select name="photo_time_time" class="maine-keyinm"  >
         <option value="9:00:00">AM 9:00</option>
         <option value="10:00:00">AM 10:00</option>
         <option value="11:00:00">AM 11:00</option>
         <option value="12:00:00">PM 12:00</option>
         <option value="13:00:00">PM 1:00</option>
         <option value="14:00:00">PM 2:00</option>
         <option value="15:00:00">PM 3:00</option>
         <option value="16:00:00">PM 4:00</option>
         <option value="17:00:00">PM 5:00</option>
         <option value="18:00:00">PM 6:00</option>
       </select></li>
      <li class="mainf-1g">看樣</li><li class="mainf-1g2"><input name="proof_time" type="text"  class="maine-keyini datepicker _validate_form_required"/>
      <select name="proof_time_time" class="maine-keyinm" >
          <option value="9:00:00">AM 9:00</option>
         <option value="10:00:00">AM 10:00</option>
         <option value="11:00:00">AM 11:00</option>
         <option value="12:00:00">PM 12:00</option>
         <option value="13:00:00">PM 1:00</option>
         <option value="14:00:00">PM 2:00</option>
         <option value="15:00:00">PM 3:00</option>
         <option value="16:00:00">PM 4:00</option>
         <option value="17:00:00">PM 5:00</option>
         <option value="18:00:00">PM 6:00</option>
       </select>
       </li>
      <li class="mainf-1g">取件</li><li class="mainf-1g2"><input name="pickup_time" type="text"  class="maine-keyini datepicker _validate_form_required"/>
      <select name="pickup_time_time" class="maine-keyinm"  >
          <option value="9:00:00">AM 9:00</option>
         <option value="10:00:00">AM 10:00</option>
         <option value="11:00:00">AM 11:00</option>
         <option value="12:00:00">PM 12:00</option>
         <option value="13:00:00">PM 1:00</option>
         <option value="14:00:00">PM 2:00</option>
         <option value="15:00:00">PM 3:00</option>
         <option value="16:00:00">PM 4:00</option>
         <option value="17:00:00">PM 5:00</option>
         <option value="18:00:00">PM 6:00</option>
       </select>
       </li>
      </ul>
   </div>
    <div class="mainf-3">
    <ul>
      <li class="mainf-1h">攝影師</li>
      <li class="mainf-1b"><img src="images/line5.gif" width="676" height="7" /></li>
      <?php
      	$dtWorder = new DataTable(constant('DB_TABLE_WORKER'));
      	$workerList = $dtWorder->get_list('`type`=4','name');
      	foreach($workerList as $tmpData)
      	{
      ?>
      	<li class="mainf-1c"><input type="checkbox" class="jq_html_selector_photo" name="photo_person_list[]" value="<?php echo $tmpData['name'];?>"/>&nbsp;<?php echo $tmpData['name'];?></li>
      <?php }?>
      </ul>
     </div>
     
     <div class="mainf-3">
    <ul>
      <li class="mainf-1h">造型師</li>
      <li class="mainf-1b"><img src="images/line5.gif" width="676" height="7" /></li>
        <?php
      	$dtWorder = new DataTable(constant('DB_TABLE_WORKER'));
      	$workerList = $dtWorder->get_list('`type`=5','name');
      	foreach($workerList as $tmpData)
      	{
      ?>
      	<li class="mainf-1c"><input type="checkbox" class="jq_html_selector_dress" name="dress_person_list[]" value="<?php echo $tmpData['name'];?>"/>&nbsp;<?php echo $tmpData['name'];?></li>
      <?php }?>
      </ul>
     </div>
     
  </div><!-- start #mainf //-->
    
     
  <script language="javascript">
  function submitForm()
  {
  	var valid = true;
  	$('.form_value_error').removeClass('form_value_error');
  	/*
  	//check photo time
    	if($('input[name=photo_time]').val() == '')
    	{
    		$('input[name=photo_time]').addClass('form_value_error');
    		valid = false;
    	}
    	//proof time
    	if($('input[name=proof_time]').val() == '')
    	{
    		$('input[name=proof_time]').addClass('form_value_error');
    		valid = false;
    	}
    	//pickup time
    	if($('input[name=pickup_time]').val() == '')
    	{
    		$('input[name=pickup_time]').addClass('form_value_error');
    		valid = false;
    	}*/
    if(valid)
    {
   		 document.forms[0].submit();
    }
  	return false;
  }
  </script>
    <div id="paged"><!-- start #pagec //-->
    <a href="add-cosc.php?id=<?php echo $orderManager->getId();?>"><img src="images/pagec2-prev.gif" width="77" height="29" /></a><a href="#" onclick="return submitForm();"><img src="images/pagec2-next.gif" width="77" height="29" /></a>
  </div><!-- end #paged //-->
</div><!-- end #tita //-->
</form>
</div><!-- end #main //-->
<?php include 'page_footer.php';?>